package prickworlds.graphics;

import static org.lwjgl.opengl.GL11.*;

import org.lwjgl.util.Color;

public class ParticleType {
	private Texture texture;
	private int fullLife;
	private ColorGradient colorGradient;

	public ParticleType(Texture texture) {
		this.texture = texture;
	}

	public void setTexture(Texture texture) {
		this.texture = texture;
	}

	public Texture getTexture() {
		return texture;
	}

	public void setFullLife(int fullLife) {
		this.fullLife = fullLife;
	}

	public int getFullLife() {
		return fullLife;
	}
	
	public ColorGradient getColorGradient() {
		return colorGradient;
	}

	public void setColorGradient(ColorGradient colorGradient) {
		this.colorGradient = colorGradient;
	}

	public Color getColor(float pos) {
		return colorGradient.get(pos);
	}

	public static FullTexture createStandardParticleTexture(int size) {
		byte[] data = new byte[size * size];

		for (int i = 0; i < size; i++) {
			for (int j = 0; j < size; j++) {
				int x = i - size / 2;
				int y = j - size / 2;
				double dist = size / 2 - Math.sqrt(x * x + y * y);
				if (dist < 0)
					dist = 0;
				data[i * size + j] = (byte) (dist * 800 / size / 2);
			}
		}

		return FullTexture.createTexture(size, size, data, GL_ALPHA);
	}
}
